package com.example.controller;

import com.example.dto.UserDO;
import com.example.dto.UserDTO;
import com.example.validator.ValidGroup;
import com.example.vo.UserResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Email;

@RestController
@Slf4j
@RequestMapping("/user")
public class ValidController {
    @PostMapping("")
    public String test1(@Validated @RequestBody UserDTO userDTO){
        log.info("validEntity is {}", userDTO);
        return "test1 valid success";
    }

    @PutMapping(value = "")
    public String test2(@Validated @RequestBody UserDTO userDTO){
        log.info("validEntity is {}", userDTO);
        return "test2 valid success";
    }

    @PostMapping(value = "/test3")
    public String test3(@Email String email){
        log.info("email is {}", email);
        return "email valid success";
    }

    @PostMapping("/add")
    public String test4(@Validated(value = ValidGroup.Crud.Create.class) @RequestBody UserDO userDO){
        log.info("validEntity is {}", userDO);
        return "test1 valid success";
    }

    @PutMapping(value = "/update")
    public String test5(@Validated(value = ValidGroup.Crud.Update.class) @RequestBody UserDO userDO){
        log.info("validEntity is {}", userDO);
        return "test2 valid success";
    }

    @GetMapping(value = "/{id}")
    public UserResult test6(@PathVariable String id) {
        UserResult userResult = new UserResult();
        userResult.setAge(15);
        userResult.setEmail("123@qq.com");
        userResult.setId(id);
        userResult.setSex("F");
        return userResult;
    }
}
